//
//  BaseViewController.swift
//  波波微博
//
//  Created by wave on 15/7/27.
//  Copyright © 2015年 wave. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController,VisitorLoginViewDelegate {

    //判断用户是否登陆
//    var userLogin = UserAccount.loadAccount() != nil
//    var userLogin = false
    //取出用户是否登陆
    var userLogin = UserAccount.userLogn
    
    
    var visitorView : VisitorLoginView?
    
    override func loadView() {
        
        // 根据用户是否登陆了来确定登陆到哪个界面
        userLogin ? super.loadView() : setUpView()
    }
    
//  设置访客视图
    private func setUpView(){
        
        visitorView = VisitorLoginView()
    
        view = visitorView
        
        //⑥ 设置代理实现方法
        visitorView?.delegate = self
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillLogin")
    }
    
    //⑦ 实现代理方法
    func visitorLoginViewWillLogin(){
    
//        print("登陆")
        
       let nav = UINavigationController(rootViewController: OAuthViewController())

        presentViewController(nav, animated: true, completion: nil)
        
    }
    
    func visitorLoginViewWillRegister(){
    
        print("注册")
    }
}
